<template>
       <div class="my-tag">
              <input
              v-if="isShow"
              v-focus
              @blur="isShow = false"
                v-model="inputTag"
                @keydown.enter="ChangeTag"
                class="input"
                type="text"
                placeholder="输入标签"
              />
              <div v-else @dblclick="show"  class="text">{{value}}</div>
            </div>
</template>

<script>
export default {
  // name: 'MyTag',
//父传子的数据v-model item.tag
 props:{
    value:{
      type:String,
      required: true
    }
  },
  
  data() {
    return {
      isShow:false,
      inputTag:''
    };
  },
  methods: {
    //子传父
    ChangeTag(){
      this.$emit('input',this.inputTag)
    // 隐藏 input
      this.isShow = false
    },
    show(){
      this.isShow = true
      //数据回显
      this.inputTag=this.value
    }
  },
};
</script>

<style lang="less" scoped>
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}

</style>